//
//  MOTabBarViewController.m
//  MobileOffice
//
//  Created by 晓 on 2019/5/30.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOTabBarViewController.h"
#import "MONavigationController.h"
#import "MOHomeViewController.h"
#import "MOCommonUseViewController.h"
#import "MONoticeViewController.h"
#import "MOSetUpViewController.h"

@interface MOTabBarViewController ()

@end

@implementation MOTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIColor *titleHighlightedColor = KTabbarBlueColor;
    
    UIColor *titleNormalColor = KTabbarBlackColor;
    
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       titleHighlightedColor, NSForegroundColorAttributeName,
                                                       nil] forState:UIControlStateSelected];
    
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       titleNormalColor, NSForegroundColorAttributeName,
                                                       nil] forState:UIControlStateNormal];
    //隐藏黑色线条
    CGRect rect = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.tabBar setBackgroundImage:img];
    [self.tabBar setShadowImage:img];
    [self.tabBar setBackgroundColor:KWhiteColor];
    //添加子控制器
    [self addChildControllers];
}

//添加控制器
- (void)addChildControllers{
    MOHomeViewController *homeVC = [[MOHomeViewController alloc] init];
    homeVC.title = @"首页";
    homeVC.tabBarItem.image = [[UIImage imageNamed:@"tabbar_home_nomal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    homeVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_home_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    MONavigationController *navHome = [[MONavigationController alloc]initWithRootViewController:homeVC];
    
    MOCommonUseViewController *commonUseVC = [[MOCommonUseViewController alloc]init];
    commonUseVC.title = @"常用";
    commonUseVC.tabBarItem.image = [[UIImage imageNamed:@"tabbar_common_nomal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    commonUseVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_common_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    MONavigationController *navCommonUse = [[MONavigationController alloc]initWithRootViewController:commonUseVC];
    
    MONoticeViewController *noticeVC = [[MONoticeViewController alloc] init];
    noticeVC.title = @"通知";
    noticeVC.tabBarItem.image = [[UIImage imageNamed:@"tabbar_notice_nomal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    noticeVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_notice_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    MONavigationController *navNotice = [[MONavigationController alloc]initWithRootViewController:noticeVC];
    
    MOSetUpViewController *setUpVC = [[MOSetUpViewController alloc] init];
    setUpVC.title = @"设置";
    setUpVC.tabBarItem.image = [[UIImage imageNamed:@"tabbar_set_nomal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    setUpVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_set_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    MONavigationController *navSetUp = [[MONavigationController alloc]initWithRootViewController:setUpVC];
    
    [self addChildViewController:navHome];
    [self addChildViewController:navCommonUse];
    [self addChildViewController:navNotice];
    [self addChildViewController:navSetUp];
}

- (BOOL)shouldAutorotate {
    return NO;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
